package com.kust.smarthome.web.controller;

import com.kust.smarthome.web.service.IPersonDetailsService;
import com.kust.smarthome.web.vo.PersonDetailsVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;


@RestController
@RequestMapping("/personDetails")
@Api(value = "关系人相关操作", tags = {"user-tag"})
@Slf4j
public class PersonDetailsController {

    @Resource
    private IPersonDetailsService personDetailsService;

    @PostMapping("/update")
    @Transactional
    public boolean updatePersonDetails(@Validated PersonDetailsVo personDetailsVo, BindingResult result) throws IOException {

        if (result.hasErrors()) {
            log.error(result.getFieldError().getDefaultMessage());
            return false;
        }

        return personDetailsService.updatePersonDetails(personDetailsVo);
    }
}


